Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to skip unknown fields instead of error #36

Merged
merged 1 commit into from
May 9, 2022

Conversation

jknovi
Copy link

@jknovi jknovi commented Mar 26, 2022

What?

Allow skipping unknown fields when deserializing.

I added a flag to to the builder, so this behavior is opt-in, keeping
the old behavior (error out for unknown fields) as default.

Why?

This is mostly required for forward compatibility, when new fields
are added, any old instance will fail to deserialize a message
serialized with a newer version. This is also aligned with prost that
skips any unknown field too.

How?

Added a special variant GeneratedField::__SkipField__ that is used every time an unknown field is encountered, which then is used to consume and ignore the value of the field. This will be added only if the skip_unknown_fields flag is set.

To set the flag, a new Builder::skip_unknown_fields function was added.

Other notes

I generated the code for the tests twice, to test the skip functionality properly. This may not be the best way as it may not scale, but didn't wanted to impose any particular style on that one. I'm totally open to work it out.

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work on this, this will be an awesome feature to have 👍

I've left some comments around testing, I think it would be good to avoid test duplication, and making the build.rs even more complex than they already are. I left some ideas on how we might simplify this. I would also like to see some tests of the unknown fields behaviour.

If you could also please sign the CLA, this will allow me to get this in once ready 😄

pbjson-build/src/generator/message.rs Show resolved Hide resolved
pbjson-build/src/generator/message.rs Show resolved Hide resolved
pbjson-build/src/lib.rs Outdated Show resolved Hide resolved
pbjson-test/build.rs Outdated Show resolved Hide resolved
pbjson-test/src/lib.rs Outdated Show resolved Hide resolved
pbjson-test/src/lib.rs Outdated Show resolved Hide resolved
@jknovi
Copy link
Author

jknovi commented Apr 4, 2022

Hi, thanks for looking at this and the feedback!

Sorry for the late reply, got emergency surgery last week :( so didn't took a look at this, I'm already feeling better, although my capacity will be a little limited, so I may move slowly with this one, but hopefully will have all the comments addressed soon.

Thanks!

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely no rush on this, feel free to take as long as you need and focus on your recovery 😄

FWIW I would be happy to take a stab at fleshing out the tests for this if you would like, otherwise happy to leave this with you, just let me know

pbjson-build/src/generator/message.rs Show resolved Hide resolved
pbjson-build/src/generator/message.rs Show resolved Hide resolved
pbjson-test/src/lib.rs Outdated Show resolved Hide resolved
pbjson-test/src/lib.rs Outdated Show resolved Hide resolved
@jknovi
Copy link
Author

jknovi commented Apr 29, 2022

Sorry for the delay, I'm now recovered and with enough time to look at it, also, if you want to take a stab to removing the duplication from the test I'm ok with that.

BTW, I checked and was added to the coorporate CLA for Amazon-influxData last week got the confirmation from the influxData side, not sure if I need to provide anything else, let me know.

@tustvold
Copy link
Contributor

tustvold commented May 9, 2022

Glad to hear your feeling better, sorry it's taken so long to get back to you, been a bit swamped 😅

I'll take a stab at reducing the test duplication

@tustvold tustvold force-pushed the main branch 2 times, most recently from 141970d to d6454f8 Compare May 9, 2022 09:14
@tustvold tustvold changed the title Feat: Add flag to skip unknown fields instead of error feat: add flag to skip unknown fields instead of error May 9, 2022
This is mostly required for forward compatibility, when new fields
are added, any old instance will fail to deserialize a message
serialized with a newer version. This is also aligned with prost that
skips any unknown field too.

I added a flag to to the builder, so this behavior is opt-in, keeping
the old behavior (error out for unknown fields) as default.
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again 👍

@tustvold tustvold added the automerge Put in the merge queue label May 9, 2022
@kodiakhq kodiakhq bot merged commit caa8962 into influxdata:main May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Put in the merge queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants